#include "font.h"
#include "lcd.h"
#include "jpg_display.h"
#include "ts.h"
#include "linux_list.h"


typedef struct pic 
{
    char jpeg0[100];
    char jpeg1[100];
    char jpeg2[100];
    linuxlist list;
}linklist,*listnode;

void init_value(listnode pic1,listnode head,char *jpeg0,char *jpeg1,char *jpeg2)
{
    
    list_add_tail(&(pic1->list),&(head->list));
    strcpy(pic1->jpeg0,jpeg0);
    strcpy(pic1->jpeg1,jpeg1);
    strcpy(pic1->jpeg2,jpeg2);
}

void input1()
{
    printf("输出");
}

void show(listnode p,struct lcd lcd)
{
    int width,height;
    init_jpg(p->jpeg1,lcd.map,0,0,&width,&height);
    init_jpg(p->jpeg0,lcd.map,800-width,240,&width,&height);
    init_jpg(p->jpeg2,lcd.map,800-width,240,&width,&height);

    // init_jpg(p->jpeg2,lcd.map,10,10,&width,&height);
}

int main(int argc, char *argv[])
{
    struct lcd lcd;
    init_lcd(&lcd);
    int x,y,width,height,width1,height1;
    listnode pic = malloc(sizeof(linklist));
    INIT_LIST_HEAD(&(pic->list));
    for(int  i = 1;i<=3;i++)
    {
        listnode new = malloc(sizeof(linklist));
        char *jpeg0 = "left.jpg";
        char *jpeg4 = ".jpg";
        char jpeg1[20];
        snprintf(jpeg1, sizeof(jpeg1), "%d.jpg", i);
        char *jpeg2 = "right.jpg";
        init_value(new,pic,jpeg0,jpeg1,jpeg2);
    }
   
    width1 = 100;
    height1 = 100;
    listnode p = list_next_entry(pic,list);

    show(p,lcd);
    while(1)
    {   
        init_ts(&x,&y);
        if(x >= 0 && x<=width1 && y>=240 && y <= 240+height1)
        {
            p = list_next_entry(p,list);
            if(p == pic)
            {
                init_jpg("black.jpg",lcd.map,0,0,&width,&height);
                init_font(48);
                show_font("已经是第一张了",450,210,300,80,0xff000000);
                uninit_font();
                continue;
            }
            show(p,lcd);
        }
        else if(x >= 800-width1 && x<=800 && y>=240 && y <= 240+height1)
        {
            p = list_prev_entry(p,list);
            if(p == pic)
            {
                init_jpg("black.jpg",lcd.map,0,0,&width,&height);
                init_font(48);
                show_font("已经是最后一张了",450,210,300,80,0xff000000);
                uninit_font();
                continue;
            }
            show(p,lcd);
        }
    }
    return 0;
}